package org.openotdr.server.controller;

import org.openotdr.server.AnalyzerPropertyBuilder;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import com.miyake.rest.DataColumn;
import com.miyake.rest.Value;
import com.miyake.rest.WebServiceProperty;
import com.miyake.rest.Value.SubUnit;

public class AnalyzeController extends Controller {

    @Override
    public Navigation run() throws Exception {
        if (this.isGet()) {
            AnalyzerPropertyBuilder builder = new AnalyzerPropertyBuilder();
            WebServiceProperty prop = builder.getProperty();
            prop.getValues().add(new Value("splice", "Splice Loss", "0.2", SubUnit.None, "dB"));
            prop.getValues().add(new Value("refl", "Reflect", "30", SubUnit.None, "dB"));
            prop.getValues().add(new Value("end", "End", "30.0", SubUnit.None, "dB"));
            this.response.getWriter().print(prop.toXML());
        }
        else if (this.isPost()) {
            AnalyzerPropertyBuilder builder = new AnalyzerPropertyBuilder();
            WebServiceProperty prop = builder.getProperty();
            prop.getValues().add(new Value("length", "Fiber length", "102.0", SubUnit.Killo, "m"));
            prop.getValues().add(new Value("conn", "Connection", "2", SubUnit.None, "None"));
            prop.getValues().add(new Value("loss", "Total Loss", "2.43", SubUnit.None, "dB"));
            
            String[] dist = {"2.3", "5.4", "6.4"};
            prop.getData().add(new DataColumn("Distance", dist));
            prop.getData().add(new DataColumn("Splice", dist));
            prop.getData().add(new DataColumn("Reflect", dist));
            this.response.getWriter().print(prop.toXML());            
        }
        
        return null;//forward("analyze.jsp");
    }
}
